package com.fc.test.service;

import java.util.List;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.NoticeInfoMapper;
import com.fc.test.model.auto.NoticeInfo;
import com.fc.test.model.auto.NoticeInfoExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 公告信息 NoticeInfoService
 * @Title: NoticeInfoService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:22:04  
 **/
@Service
public class NoticeInfoService implements BaseService<NoticeInfo, NoticeInfoExample>{
	@Autowired
	private NoticeInfoMapper noticeInfoMapper;
	
      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<NoticeInfo> list(Tablepar tablepar,NoticeInfo record){
	        NoticeInfoExample testExample=new NoticeInfoExample();
	        testExample.createCriteria().andLikeQuery(record);
	        testExample.setOrderByClause("id ASC");
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<NoticeInfo> list= noticeInfoMapper.selectByExample(testExample);
	        PageInfo<NoticeInfo> pageInfo = new PageInfo<NoticeInfo>(list);
	        return  pageInfo;
	 }

	public PageInfo<NoticeInfo> listForSys(Tablepar tablepar,NoticeInfo record){
		NoticeInfoExample testExample=new NoticeInfoExample();
		testExample.createCriteria().andLikeQuery(record);
		testExample.setOrderByClause("id ASC");
		if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
			testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<NoticeInfo> list= noticeInfoMapper.selectByExample(testExample);
		PageInfo<NoticeInfo> pageInfo = new PageInfo<NoticeInfo>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			NoticeInfoExample example=new NoticeInfoExample();
			example.createCriteria().andIdIn(stringB);
			return noticeInfoMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public NoticeInfo selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return noticeInfoMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(NoticeInfo record) {
		return noticeInfoMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(NoticeInfo record) {
				
		record.setId(null);
		
				
		return noticeInfoMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(NoticeInfo record, NoticeInfoExample example) {
		
		return noticeInfoMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(NoticeInfo record, NoticeInfoExample example) {
		
		return noticeInfoMapper.updateByExample(record, example);
	}

	@Override
	public List<NoticeInfo> selectByExample(NoticeInfoExample example) {
		
		return noticeInfoMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(NoticeInfoExample example) {
		
		return noticeInfoMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(NoticeInfoExample example) {
		
		return noticeInfoMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param noticeInfo
	 * @return
	 */
	public int checkNameUnique(NoticeInfo noticeInfo){
		NoticeInfoExample example=new NoticeInfoExample();
		example.createCriteria().andStatusEqualTo(noticeInfo.getStatus());
		List<NoticeInfo> list=noticeInfoMapper.selectByExample(example);
		return list.size();
	}


}
